import { Component, Vue, Inject } from 'vue-property-decorator';

import { IUserClass } from '@/shared/model/user-class.model';
import UserClassService from './user-class.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class UserClassDetails extends Vue {
  @Inject('userClassService') private userClassService: () => UserClassService;
  @Inject('alertService') private alertService: () => AlertService;

  public userClass: IUserClass = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.userClassId) {
        vm.retrieveUserClass(to.params.userClassId);
      }
    });
  }

  public retrieveUserClass(userClassId) {
    this.userClassService()
      .find(userClassId)
      .then(res => {
        this.userClass = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
